package biometria.server.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import biometria.server.dao.BaseDAO;

public class BaseDAOImpl implements BaseDAO {
	
	private Logger logger = Logger.getLogger(BaseDAOImpl.class);

	@Override
	public void closeConnection(Connection con) {
		try {
			if (con != null && !con.isClosed()) {
				con.close();
			}
		} catch (SQLException e) {
			logger.error("Error while trying to close connection.\n", e);
		}
	}

	@Override
	public void closeStatement(PreparedStatement stmt) {
		try {
			if (stmt != null && !stmt.isClosed()) {
				stmt.close();
			}
		} catch (SQLException e) {
			logger.error("Error while trying to close statement.\n", e);
		}
	}

	@Override
	public void closeResultSet(ResultSet rs) {
		try {
			if (rs != null && !rs.isClosed()) {
				rs.close();
			}
		} catch (SQLException e) {
			logger.error("Error while trying to close resultset.\n", e);
		}
	}

	@Override
	public void rollback(Connection con) {
		try {
			if (con != null && !con.isClosed()) {
				con.rollback();
			}
		} catch (SQLException e) {
			logger.error("Error while trying to rollback connection.\n", e);
		}
		
	}
	
}
